package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TMembershipConditions;
import com.ruoyi.system.service.ITMembershipConditionsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 入会条件信息，存储会员入会条件的各个版本及其状态Controller
 * 
 * @author ruoyi
 * @date 2025-08-25
 */
@RestController
@RequestMapping("/system/conditions")
public class TMembershipConditionsController extends BaseController
{
    @Autowired
    private ITMembershipConditionsService tMembershipConditionsService;

    /**
     * 查询入会条件信息，存储会员入会条件的各个版本及其状态列表
     */
    @PreAuthorize("@ss.hasPermi('system:conditions:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMembershipConditions tMembershipConditions)
    {
        startPage();
        List<TMembershipConditions> list = tMembershipConditionsService.selectTMembershipConditionsList(tMembershipConditions);
        return getDataTable(list);
    }


    /*导出入会信息 TODO
    *   是否可以更改为word版本      */
    @PreAuthorize("@ss.hasPermi('system:conditions:export')")
    @Log(title = "入会条件信息，存储会员入会条件的各个版本及其状态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TMembershipConditions tMembershipConditions)
    {
        List<TMembershipConditions> list = tMembershipConditionsService.selectTMembershipConditionsList(tMembershipConditions);
        ExcelUtil<TMembershipConditions> util = new ExcelUtil<TMembershipConditions>(TMembershipConditions.class);
        util.exportExcel(response, list, "入会条件信息，存储会员入会条件的各个版本及其状态数据");
    }

    /**
     * 获取入会条件信息，存储会员入会条件的各个版本及其状态详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:conditions:query')")
    @GetMapping(value = "/{conditionId}")
    public AjaxResult getInfo(@PathVariable("conditionId") Long conditionId)
    {
        return success(tMembershipConditionsService.selectTMembershipConditionsByConditionId(conditionId));
    }

    /**
     * 新增入会条件信息，存储会员入会条件的各个版本及其状态
     */
    @PreAuthorize("@ss.hasPermi('system:conditions:add')")
    @Log(title = "入会条件信息，存储会员入会条件的各个版本及其状态", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMembershipConditions tMembershipConditions)
    {
        return toAjax(tMembershipConditionsService.insertTMembershipConditions(tMembershipConditions));
    }

    /**
     * 修改入会条件信息，存储会员入会条件的各个版本及其状态
     */
    @PreAuthorize("@ss.hasPermi('system:conditions:edit')")
    @Log(title = "入会条件信息，存储会员入会条件的各个版本及其状态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMembershipConditions tMembershipConditions)
    {
        return toAjax(tMembershipConditionsService.updateTMembershipConditions(tMembershipConditions));
    }

    /**
     * 删除入会条件信息，存储会员入会条件的各个版本及其状态
     */
    @PreAuthorize("@ss.hasPermi('system:conditions:remove')")
    @Log(title = "入会条件信息，存储会员入会条件的各个版本及其状态", businessType = BusinessType.DELETE)
	@DeleteMapping("/{conditionIds}")
    public AjaxResult remove(@PathVariable Long[] conditionIds)
    {
        return toAjax(tMembershipConditionsService.deleteTMembershipConditionsByConditionIds(conditionIds));
    }

    /*C端：查看最新发布的入会条件*/
    @PreAuthorize("@ss.hasPermi('system:conditions:query')")
    @GetMapping("/c/firstActive")
    public AjaxResult getInfo(TMembershipConditions membershipConditions)
    {
        return success(tMembershipConditionsService.selectFirstActiveCondition());
    }
}
